package com.fjec.paid.schedule.handler;

import com.fjec.paid.service.IBizOrderRefundService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Component
@Slf4j
public class RefundHandler {

    @Resource
    private IBizOrderRefundService bizOrderRefundService;

    @Transactional(rollbackFor = Throwable.class)
    public void handle(int limit, int minutes) {
        List<Map<String, Object>> refunds = bizOrderRefundService.getRefundInfo(limit, minutes);
        refunds.forEach(r -> {
            try {
                bizOrderRefundService.doRefund(r);
            } catch (Exception e) {
                log.error("RefundHandler.handle error : %s", e.getMessage());
            }
        });

    }
}
